﻿namespace Neovolve.Extensibility.ReSharper
{
    using System;
    using JetBrains.ReSharper.Psi;
    using JetBrains.ReSharper.Psi.CSharp;
    using JetBrains.ReSharper.Psi.CSharp.Tree;
    using JetBrains.ReSharper.Psi.Tree;

    /// <summary>
    /// The reference expression node descriptor.
    /// </summary>
    /// <remarks>
    /// A reference expression occurs for direct type references.
    ///   For example <c>int.MaxValue</c>.
    /// </remarks>
    internal class PredefinedTypeExpressionNodeDescriptor : NodeDescriptor
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PredefinedTypeExpressionNodeDescriptor"/> class.
        /// </summary>
        /// <param name="node">
        /// The node.
        /// </param>
        public PredefinedTypeExpressionNodeDescriptor(ITreeNode node)
            : base(node)
        {
        }

        /// <summary>
        /// Creates the alias type node.
        /// </summary>
        /// <returns>
        /// A <see cref="ITreeNode"/> value.
        /// </returns>
        public override ITreeNode CreateAliasTypeNode()
        {
            throw new InvalidOperationException();
        }

        /// <summary>
        /// Creates the CLR type node.
        /// </summary>
        /// <returns>
        /// A <see cref="ITreeNode"/> value.
        /// </returns>
        public override ITreeNode CreateClrTypeNode()
        {
            IPsiModule project = Node.GetPsiModule();

            return CSharpElementFactory.GetInstance(project).CreateTypeUsageNode(TypeMapping.ClrTypeName);
        }

        /// <summary>
        /// Creates the name of the node for type.
        /// </summary>
        /// <param name="typeName">
        /// Name of the type.
        /// </param>
        /// <returns>
        /// A <see cref="ITreeNode"/> value.
        /// </returns>
        protected override ITreeNode CreateNodeForTypeName(String typeName)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Gets a value indicating whether the node is supported by this descriptor.
        /// </summary>
        /// <value>
        /// <c>true</c> if the node is supported by this descriptor; otherwise, <c>false</c>.
        /// </value>
        public override Boolean IsSupportedNode
        {
            get
            {
                return Node is IPredefinedTypeExpressionNode;
            }
        }
    }
}